package org.pointex.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
	/**
	  * 得到本周周一
	  *
	  * @return yyyy-MM-dd
	  */
	 public static Date getMondayOfThisWeek() {
		  Calendar c = Calendar.getInstance();
		  int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
		  if (day_of_week == 0)
		   day_of_week = 7;
		  c.add(Calendar.DATE, -day_of_week + 1);
		  return c.getTime();
	 }
	 
	 
	 /**
	  * 得到本周周日
	  *
	  * @return yyyy-MM-dd
	  */
	 public static Date getSundayOfThisWeek() {
	  Calendar c = Calendar.getInstance();
	  int day_of_week = c.get(Calendar.DAY_OF_WEEK) - 1;
	  if (day_of_week == 0)
	   day_of_week = 7;
	  c.add(Calendar.DATE, -day_of_week + 7);
	  return c.getTime();
	 }
	 
	 /**
	  * 日期转换 yyyy-MM-dd
	  * @param args
	  */
	 public static String formatDate_YYYYMMDD(Date dateTime){
		 SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
		return dateFormater.format(dateTime);
	 }
	 
	 /**
	  * 日期转换 yyyy-MM-dd HH:mm:ss
	  * @param args
	  */
	 public static String formatDate_YYYYMMDDHHMMSS(Date dateTime){
		 SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return dateFormater.format(dateTime);
	 }
	 
	 
	 public static void main(String[] args) {
		System.out.println("1"+getMondayOfThisWeek());
		System.out.println("2"+getSundayOfThisWeek());
	}
}
